<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-18
 * Time: 12:00
 */

namespace app\api\controller\v1;


use app\api\model\ProjectHatch;
use app\api\model\ProjectHatchLook;
use app\api\service\project\LookOrderSer;
use app\api\service\project\LookSer;
use app\api\service\Token;

class ProjectLook
{
    // 判断评价权限
    public function judgeProjectLook($project_hatch_id)
    {
        $uid = Token::getCurrentUid();
        $projectHatch = ProjectHatch::get($project_hatch_id);
        if($projectHatch['user_id'] == $uid) {
            return [
                'isValid' => true
            ];
        } else {
            $info = Token::judgeProjectHatchLook($project_hatch_id);
            if ($info) {
                return [
                    'isValid' => true
                ];
            } else {
                return [
                    'isValid' => false
                ];
            }
        }
    }

    // 创建订单
    public function createOrder($project_hatch_id)
    {
        $hatchLookSer = new LookOrderSer($project_hatch_id);
        return $hatchLookSer->entrance();
    }

    // 创建查看信息
    public function createData($project_hatch_id)
    {
        $hatchLookSer = new LookSer($project_hatch_id);
        return $hatchLookSer->entrance();
    }


    // 获取用户查看的项目
    public function getLookData()
    {
        $uid = Token::getCurrentUid();
        $time = time();
        $where[] = ['start_time','<=',$time];
        $where[] = ['end_time','>=',$time];
        $where[] = ['user_id','=',$uid];
        return ProjectHatchLook::where($where)
            ->with('project')
            ->select()->toArray();
    }
}